class MembersController < ApplicationController
  
  
  before_filter :login_required, :except => [:new, :create]

  #page to register new member
  def new
  end
  
  def index
    @members = Member.find(:all, :order => 'created_at DESC')
  end
  
  #show the page's member
  def show
    @member = Member.find_by_login(params[:id])
    @w_reservations = @member.week_reservations 
    @categories = Category.find(:all)
  end
  
  def edit
    @member = Member.find(session[:member_id])
  end
  
  def update
    @member = Member.find(session[:member_id])
    @member.update_attributes(params[:member])
    redirect_to member_path(@member)
  end

  #create and saves new member and redirects to thank you page
  def create
    cookies.delete :auth_token
    reset_session
    @member = Member.new(params[:member])
    @member.save!
    self.current_member = @member
    redirect_to member_path(@member)
    flash[:success] = "Thanks for signing up!"
  rescue ActiveRecord::RecordInvalid
    render :action => 'new'
  end


end
